using System;
using System.Collections.Generic;
using System.Text;
using DDW.Collections;

namespace DDW
{
	public class MethodNode : MemberNode
	{
		private NodeCollection<ParamDeclNode> parameters;
		public NodeCollection<ParamDeclNode> Params
		{
			get { if (parameters == null) parameters = new NodeCollection<ParamDeclNode>(); return parameters; }
			set { parameters = value; }
        }

		private BlockStatement statementBlock = new BlockStatement();
		public BlockStatement StatementBlock
		{
			get { return statementBlock; }
		}

		public override void ToSource(StringBuilder sb)
		{
			if (attributes != null)
			{
				attributes.ToSource(sb);
				this.NewLine(sb);
			}
			this.TraceModifiers(this.Modifiers, sb);

			this.type.ToSource(sb);
			sb.Append(" ");

			this.names[0].ToSource(sb);
			sb.Append("(");

			if (parameters != null)
			{
				string comma = "";
				for (int i = 0; i < parameters.Count; i++)
				{
					sb.Append(comma);
					comma = ", ";
					parameters[i].ToSource(sb);
				}
			}

			sb.Append(")");
			this.NewLine(sb);

			statementBlock.ToSource(sb);
		}
	}
}
